public class demo2 {
    private static Object locker1= new Object();
    private static Object locker2 = new Object();
    private static Object locker3 = new Object();
    public static void main(String[] args) throws InterruptedException {
       /* 使用三个锁, 分别控制.
                有三个线程，分别只能打印A，B和C
        要求按顺序打印ABC，打印10次
      */
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                synchronized (locker1){
                    try {
                        locker1.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.print("A" );
                synchronized (locker2){
                    locker2.notify();
                }
            }

        });
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                synchronized (locker2){
                    try {
                        locker2.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.print("B" );
                synchronized (locker3) {
                    locker3.notify();
                }
            }


        });
        Thread t3 = new Thread(()->{
            for (int i = 0; i <10 ; i++) {
                synchronized (locker3){
                    try {
                        locker3.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("C" );
                synchronized (locker1){
                    locker1.notify();
                }
                //System.out.println( );

            }

        });

        t1.start();
        t2.start();
        t3.start();
        Thread.sleep(100);
        synchronized (locker1){
            locker1.notify();
        }

    }

}
